package top100.tree;

import utils.TreeNode;

/**
 * @Author ZhangCuirong
 * @Date 2025/8/22 10:10
 * @description:
 */
public class Solution226 {
    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        TreeNode left = invertTree(root.left);
        TreeNode right = invertTree(root.right);
        root.left = right;
        root.right = left;
        return root;
    }

    public static void main(String[] args) {
        Solution226 solution = new Solution226();
        TreeNode root = TreeNode.buildTree(new int[]{4,2,7,1,3,6,9});
        TreeNode.show(root);
        TreeNode newRoot = solution.invertTree(root);
        TreeNode.show(newRoot);
    }
}
